<?php
session_start();
require('../conn.php');
require('../functions.php');
require('admin.php');
$page = $_GET['page'];
if (is_numeric($page) == false) {
    $page = 1;
    $page_1 = 1;
    $min = 0;
    $page_2 = $page + 1;
} else {
    if ($page > 1) {
        $page_2 = $page + 1;
        $min = ($page - 1) * 10;
        $page_1 = $page - 1;
    } else {
        $page_1 = 1;
        $min = 0;
        $page_2 = 2;
    }
}
$max = $page * 10;
$sql = "select d.* from `sharesite` d where d.`state` = 1 order by d.`id` desc limit {$min},{$max}";
$update_id = guolv($_GET['update_id']);
$state = guolv($_GET['state']);
if (is_numeric($update_id) && is_numeric($state)) {
    $mysql->query("update `sharesite` d set d.`state` = {$state} where `id`='{$update_id}'");
    echo '<script>alert(\'操作成功\');location.href=\'domain_check.php\'</script>';
    exit;
}
if ($state != null && $state != '') {
    $sql = "select d.* from `sharesite` d where d.`state` = {$state} order by `id` desc limit {$min},{$max}";
}
if ($_GET['do'] == 'search') {
    $name = guolv($_GET['name']);
    if (substr($name, 0, 1) == '#') {
        $search_id = str_replace('#', '', $name);
        $sql = "select d.* from `sharesite` d where `id`='{$search_id}' order by `id` desc limit {$min},{$max}";
    } else {
        $sql = "select d.* from `sharesite` d where d.`name` like '%{$name}%' and d.`state` <> 3 order by `id` desc limit {$min},{$max}";
    }
}
$row_sharesite = $mysql->query($sql);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>管理系统</title>
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" type="text/css" href="lib/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="stylesheets/theme.css">
    <link rel="stylesheet" href="lib/font-awesome/css/font-awesome.css">

    <script src="<?php echo $jquerysite ?>" type="text/javascript"></script>
    <!-- Demo page code -->
    <script language="JavaScript" type="text/javascript">
        // if ((navigator.userAgent.indexOf('MSIE') >= 0)
        // && (navigator.userAgent.indexOf('Opera') < 0)){
        // alert('您使用的是IE浏览器，请用chrome内核浏览器，推荐UC浏览器，360极速，猎豹等');
        // location.href='admin.php?do=exit';
        // }
    </script>
    <style type="text/css">
        #line-chart {
            height:300px;
            width:800px;
            margin: 0px auto;
            margin-top: 1em;
        }
        .brand { font-family: georgia, serif; }
        .brand .first {
            color: #ccc;
            font-style: italic;
        }
        .brand .second {
            color: #fff;
            font-weight: bold;
        }
    </style>

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="javascripts/html5.js"></script>
    <![endif]-->

    <!-- Le fav and touch icons -->
</head>

<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7"> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8"> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<body>

<div class="container-fluid">

    <div class="row-fluid">
        <div class="span9">
            <h1 class="page-title">域名检测 &nbsp;&nbsp; <a href="ucenter.php">返回首页</a></h1>
            <div class="well">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <div class="well">
                            <form class="navbar-search pull-left" action="domain_check.php" method="get">
                                <input type="hidden" name="do" value="search">
                                <input type="text" class="search-query" placeholder="搜索域名+回车" name="name">
                            </form>
                            <div class="btn-group pull-right">
                                <button class="btn"><a href="?state=1" style="color:green">使用中</a></button>
                                <button class="btn dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu">
                                    <?php
                                    for($i=0;$i<=2;$i++){
                                        switch ($i) {
                                            case '0': {
                                                echo "<li><a onclick='search_state({$i});' style=\"color:blue\">未使用</a></li>";
                                                break;
                                            }
                                            case '1': {
                                                echo "<li><a onclick='search_state({$i});' style=\"color:green\">使用中</a></li>";
                                                break;
                                            }
                                            case '2': {
                                                echo "<li><a onclick='search_state({$i});' style=\"color:red\">微信屏蔽</a></li>";
                                                break;
                                            }
                                            case '3': {
                                                echo "<li><a onclick='search_state({$i});' style=\"color:darkgrey\">已删除</a></li>";
                                                break;
                                            }
                                        }

                                    }
                                    ?>
                                </ul>
                                <a href="domain_check.php" class="btn">首页</a></button>
                                <a href="domain_check.php?page=<?php echo $page_1 ?>" class="btn"
                                   style="margin-left:5px;">上一页</a>
                                <a href="domain_check.php?page=<?php echo $page_2 ?>" class="btn"
                                   style="margin-left:5px;">下一页</a>
                            </div>
                            <table class="table">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>域名</th>
                                    <th>类型</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                foreach ($row_sharesite as $v_sharesite) {
                                    $s = $v_sharesite['state'];
                                    $btn = "";
                                    switch ($s) {
                                        case '0': {
                                            $s = '<p style="color:blue">未使用</p>';
                                            $btn = "
<a class=\"btn\" style=\"color:green\" onclick=\"update_id({$v_sharesite['id']}, 1)\" title=\"使用中\"><i class=\"icon-check\"></i></a>
<a class=\"btn\" style=\"color:red\" onclick=\"update_id({$v_sharesite['id']}, 2)\" title=\"微信屏蔽\"><i class=\"icon-remove\"></i></a>
<a class=\"btn\" style=\"color:darkgrey\" title=\"删除域名\" onclick=\"update_id({$v_sharesite['id']}, 3)\"><i class=\"icon-trash\"></i></a>";
                                            break;
                                        }
                                        case '1': {
                                            $s = '<p style="color:green">使用中</p>';
                                            $btn = "
<a class=\"btn\" style=\"color:blue\" onclick=\"update_id({$v_sharesite['id']}, 0)\" title=\"未使用\"><i class=\"icon-undo\"></i></a>
<a class=\"btn\" style=\"color:red\" onclick=\"update_id({$v_sharesite['id']}, 2)\" title=\"微信屏蔽\"><i class=\"icon-remove\"></i></a>
<a class=\"btn\" style=\"color:darkgrey\" title=\"删除域名\" onclick=\"update_id({$v_sharesite['id']}, 3)\"><i class=\"icon-trash\"></i></a>";
                                            break;
                                        }
                                        case '2': {
                                            $s = '<p style="color:red">微信屏蔽</p>';
                                            $btn = "
<a class=\"btn\" style=\"color:blue\" onclick=\"update_id({$v_sharesite['id']}, 0)\" title=\"未使用\"><i class=\"icon-undo\"></i></a>
<a class=\"btn\" style=\"color:green\" onclick=\"update_id({$v_sharesite['id']}, 1)\" title=\"使用中\"><i class=\"icon-check\"></i></a>
<a class=\"btn\" style=\"color:darkgrey\" title=\"删除域名\" onclick=\"update_id({$v_sharesite['id']}, 3)\"><i class=\"icon-trash\"></i></a>";
                                            break;
                                        }
//                                        case '3': {
//                                            $s = '<p style="color:darkgrey">已删除</p>';
//                                            $btn = "
//<a class=\"btn\" style=\"color:blue\" onclick=\"update_id({$v_sharesite['id']}, 0)\" title=\"未使用\"><i class=\"icon-undo\"></i></a>
//<a class=\"btn\" style=\"color:green\" onclick=\"update_id({$v_sharesite['id']}, 1)\" title=\"使用中\"><i class=\"icon-check\"></i></a>
//<a class=\"btn\" style=\"color:red\" onclick=\"update_id({$v_sharesite['id']}, 2)\" title=\"微信屏蔽\"><i class=\"icon-remove\"></i></a>";
//                                            break;
//                                        }
                                    }
                                    print <<<table
        <tr>
          <td>{$v_sharesite['id']}</td>
     	  <td>{$v_sharesite['name']} &nbsp;
     	    <a class="btn" style="color:blue" onclick="fn_check_domain('{$v_sharesite['name']}')" title="检测"><i class="icon-forward"></i></a>
     	    &nbsp;&nbsp;
     	    <a class="btn" style="color:red" onclick="update_id({$v_sharesite['id']}, 2)" title="微信屏蔽"><i class="icon-remove"></i></a>
     	  </td>
		  <td>{$v_sharesite['type']}</td>
		  <td>{$s}</td>
		  <td>
		    {$btn}
		  </td>
        </tr>
table;
                                } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="profile">
                    </div>
                </div>

            </div>

        </div>
    </div>


</div>

<footer>
    <hr>

    <p class="pull-right"><!--power by right--></p>


    <p><!--power by --></p>
</footer>


<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="lib/bootstrap/js/bootstrap.js"></script>
<script language="JavaScript">
    function search_state(state) {
        location.href = "?state=" + state;
    }
    function update_id(id, state) {
        var str = "";
        switch (state) {
            case 0: {
                str = " [未使用] ";
                break;
            }
            case 1: {
                str = " [使用中] ";
                break;
            }
            case 2: {
                str = " [微信屏蔽] ";
                break;
            }
            case 3: {
                str = " [已删除] ";
                break;
            }
        }
        if (confirm("状态更新为" + str + "，确定操作？")) {
            location.href = "?update_id=" + id + "&state=" + state;
        } else {
            return false;
        }
    }
    function fn_check_domain(domain) {
        if (domain) {
            location.href = 'http://' + domain;
        }
    }
</script>


</body>
</html>